import requests
from lxml import etree

url = "https://www.zbj.com/fw/?k=saas"

headers = {
"user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0"
}

resp = requests.get(url,headers=headers)
print(resp.text)
# 解析
tree = etree.HTML(resp.text)

# 获取服务商列表
# 通过网页的右键 检查，点击左上角图标，再点击网页上的元素，定位元素在html内的位置，再复制完整的xpath
# 要注意xpath如果出不来结果或者数据不对，要检查各层级并列的div是不是有属性为hidden，如果有的话不能计算在内
divList = tree.xpath("/html/body/div[1]/div/div/div[3]/div[1]/div[4]/div/div[2]/div[1]/div[2]/div")
# print(divList)
for div in divList:
    # 每一个服务商，这里的xpath可以通过复制完整的xpath之后再将父xpath改成点
    price = div.xpath("./div/div[3]/div[1]/span/text()")[0].strip("¥")
    title = "SAAS".join(div.xpath("./div/div[3]/div[2]/a/span/text()"))
    com = div.xpath("./div/div[5]/div/div/div/text()")[0]
    print(price,title,com)